package com.zoweunion.mechanic.controller;

import java.util.List;
import java.util.Map;

import com.zoweunion.mechanic.entity.TSSsVehicleTypeEntity;
import com.zoweunion.mechanic.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.service.TSSsVehicleBrandService;
import com.zoweunion.mechanic.entity.TSSsVehicleBrandEntity;


import com.zoweunion.mechanic.model.ResponseBean;
import com.github.pagehelper.PageInfo;

import javax.servlet.http.HttpServletRequest;


/**
 * 车类品牌
 *
 * @author xp
 * @email 17688825585@163.com
 * @date 2020-05-25 19:37:47
 */
@RestController
@RequestMapping("/tsssvehiclebrand")
public class TSSsVehicleBrandController extends BaseController {
    @Autowired
    private TSSsVehicleBrandService tSSsVehicleBrandService;

    /**
     * 列表
     */
    @GetMapping("/tSSsVehicleBrandList")
    public ResponseBean tSSsVehicleBrandList(@RequestParam Map<String, Object> params, HttpServletRequest request) throws MyException {
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        PageInfo info = tSSsVehicleBrandService.queryPage(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", info);
    }

    /**
     * 新增
     */
    @PostMapping("/tSSsVehicleBrandInsertUpdate")
    public ResponseBean tSSsVehicleBrandInsertUpdate(@RequestBody TSSsVehicleBrandEntity params,
                                                     HttpServletRequest request) {
        if (params.getId() != null) {
            tSSsVehicleBrandService.updateById(params);
        } else {
            params.setId(UuidUtil.get32UUID());
            tSSsVehicleBrandService.save(params);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 列表
     */
    @GetMapping("/tSSsVehicleBrandListFor")
    public ResponseBean tSSsVehicleBrandListFor(@RequestParam Map<String, Object> params, HttpServletRequest request) throws MyException {
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        List<TSSsVehicleBrandEntity> list = tSSsVehicleBrandService.tSSsVehicleBrandListFor(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", list);
    }


}
